Argh, decided not to return a string that must be freed from
authorTor Lillqvist <tml@src.gnome.org>
Thu, 3 Feb 2000 01:42:51 +0000 (01:42 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Thu, 3 Feb 2000 01:42:51 +0000 (01:42 +0000)
gtk_file_selection_get_filename after all, as that would
cause memory leaks in all apps that use it unless they
specifically checked fot the GTk+ version.

gtk_file_selection_get_filename returns the filename in the C
runtime encoding. It calls g_filename_from_utf8, but copies the
returned string to a static buffer, which is returned. I think
this is better than returning the result from g_filename_from_utf8
directly, which would mean all apps that use it would have to free
the return value. Or should this function care about this issue at
all? Maybe a new function with clearly defined semantics.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilesel.c
gtk/gtkfilesel.h

index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d557074680a0d393f9745fbe30ae2fcb35af471e..d10f1e62c2cf02184435c7a277c677cb7a4ff5ce 100644 (file)
@@ -27,6 +27,14 @@ Wed Feb  2 11:58:05 2000  Owen Taylor  <otaylor@redhat.com>
        GLib). Some cleanups: Use gbooleans. Use GStrings instead of fixed
        size buffers.
 
+       gtk_file_selection_get_filename returns the filename in the C
+       runtime encoding. It calls g_filename_from_utf8, but copies the
+       returned string to a static buffer, which is returned. I think
+       this is better than returning the result from g_filename_from_utf8
+       directly, which would mean all apps that use it would have to free
+       the return value. Or should this function care about this issue at
+       all? Maybe a new function with clearly defined semantics.
+
        * gtk/gtkfilesel.h: Add comment about
        gtk_file_selection_get_filename returning the filename in the C
        runtime's encoding.
index d3a1904364c362fddf9f7e60517ce09792ea8622..e79294864070cd61d6734139a4d882837089961c 100644 (file)
@@ -728,9 +728,10 @@ gtk_file_selection_set_filename (GtkFileSelection *filesel,
 gchar*
 gtk_file_selection_get_filename (GtkFileSelection *filesel)
 {
-  static char nothing[2] = "";
-  char *text;
+  static gchar nothing[2] = "";
+  static gchar something[MAXPATHLEN*2];
   char *filename;
+  char *text;
 
   g_return_val_if_fail (filesel != NULL, nothing);
   g_return_val_if_fail (GTK_IS_FILE_SELECTION (filesel), nothing);
@@ -741,8 +742,10 @@ gtk_file_selection_get_filename (GtkFileSelection *filesel)
   text = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
   if (text)
     {
-      filename = cmpl_completion_fullname (text, filesel->cmpl_state);
-      return g_filename_from_utf8 (filename);
+      filename = g_filename_from_utf8 (cmpl_completion_fullname (text, filesel->cmpl_state));
+      strncpy (something, filename, sizeof (something));
+      g_free (filename);
+      return something;
     }
 
   return nothing;
index 24ff5de521f77766f859bbcf69a43a93a67306ea..d5970c3f1a83d7a5180030dca0dbea6bd9276f35 100644 (file)
@@ -89,7 +89,8 @@ void       gtk_file_selection_set_filename        (GtkFileSelection *filesel,
 /* This function returns the selected filename in the C runtime's
  * multibyte string encoding, which may or may not be the same as that
  * used by GDK (UTF-8). To convert to UTF-8, call g_filename_to_utf8().
- * The returned string should be deallocated with g_free().
+ * The returned string points to a statically allocated buffer and
+ * should be copied away.
  */
 gchar*     gtk_file_selection_get_filename        (GtkFileSelection *filesel);